package mess;

public class LeeCode_1247 {
    public static void main(String[] args) {
        System.out.println(minimumSwap("xx", "yy"));
        System.out.println(minimumSwap("xxyyxyxyxx", "xyyxyxxxyx"));
    }

    private static int minimumSwap(String s1, String s2) {
        char[] chars1 = s1.toCharArray();
        char[] chars2 = s2.toCharArray();
        int len1 = chars1.length;
        int len2 = chars2.length;
        if (len1 != len2)
            return -1;
        int countA = 0;
        int countB = 0;
        for (int i = 0; i < len1; i++) {
            if (chars1[i] == chars2[i])
                continue;
            if (chars1[i] == 'x' && chars2[i] == 'y')
                countA++;
            else countB++;
        }
        return countA % 2 == countB % 2 ? countA / 2 + countB / 2 + countA % 2 * 2 : -1;
    }
}
